class Solution {
    public int returnVal(int n) {
        int sum = 0;
        while (n != 0) {
            int t = n%10;
            n /= 10;
            sum += t*t;//
        }
        return sum;
    }
    public boolean isHappy(int n) {
        int slow = returnVal(n);
        int fast = returnVal(returnVal(n));
        while (slow != fast) {
            slow = returnVal(slow);
            fast = returnVal(returnVal(fast));
        }
        if (slow == 1) {
            return true;
        }
        return false;
    }
}